/* Code for Tronixstuff chapter 1 example 2 */

// Initializations
int red = 9;
int green = 10;
int blue = 11;
int i, j; // loop variables

void setup() {
   pinMode(red,OUTPUT);
   pinMode(green,OUTPUT);
   pinMode(blue,OUTPUT);
   randomSeed(analogRead(0)); // need a random seed
}

void loop() {
   
/*    Check each LED to make sure it lights up properly by
      having it turn on gradually then off */
   // Red LED
   for (i = 0; i <= 255; i++) { // get bright
      analogWrite(red,i); // brighten the red LED
      delay(10); // short delay as analogWrite isn't instantaneous
   }
   
      analogWrite(red,0); // turn off the LED
      delay(10); // short delay as analogWrite isn't instantaneous

   // Green LED
   for (i = 0; i <= 255; i++) { // get bright
      analogWrite(green,i); // brighten the green LED
      delay(10); // short delay as analogWrite isn't instantaneous
   }
      analogWrite(green,0); // turn off the green LED
      delay(10); // short delay as analogWrite isn't instantaneous

   // Blue LED
   for (i = 0; i <= 255; i++) { // get bright
      analogWrite(blue,i); // brighten the blue LED
      delay(10); // short delay as analogWrite isn't instantaneous
   }
      analogWrite(blue,0); // turn off the blue LED
      delay(10); // short delay as analogWrite isn't instantaneous
      
   
   // Go psychadelic
   for (j = 0; j < 100; j++) {
      analogWrite(red,random(255));
      delay(10);
      
      analogWrite(green,random(255));
      delay(10);
      
      analogWrite(blue,random(255));
      delay(10);
   }
   
   analogWrite(red,0);
   delay(20);
   analogWrite(green,0);
   delay(20);
   analogWrite(blue,0);
   delay(20);
   
}
